package logic

import (
	"context"
	"gorm.io/gorm"
	"house_srv/models/mysql"

	"house_srv/house"
	"house_srv/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type HouseShowLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewHouseShowLogic(ctx context.Context, svcCtx *svc.ServiceContext) *HouseShowLogic {
	return &HouseShowLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *HouseShowLogic) HouseShow(in *house.HouseShowRequest) (*house.HouseShowResponse, error) {
	// todo: add your logic here and delete this line
	h := mysql.House{
		Model:  gorm.Model{ID: uint(in.HouseId)},
		UserId: in.UserId,
	}
	mysql.Db.Model(&h).Find(&h)

	return &house.HouseShowResponse{
		UserId:        h.UserId,
		HouseCity:     h.HouseCity,
		Address:       h.Address,
		HouseBuild:    h.HouseBuild,
		HouseFloor:    h.HouseFloor,
		HouseArea:     h.HouseArea,
		HousePrice:    float32(h.HousePrice),
		HouseDescribe: h.HouseDescribe,
		HouseCover:    h.HouseCover,
		HouseStatus:   h.HouseStatus,
	}, nil
}
